#include "splashscreen.h"

BEGIN_EVENT_TABLE(SplashScreenWindow, wxPanel)
#ifdef __WXGTK__
    EVT_PAINT(SplashScreenWindow::OnPaint)
#endif
    EVT_ERASE_BACKGROUND(SplashScreenWindow::OnEraseBackground)
END_EVENT_TABLE()


static void wxDrawSplashBitmap(wxDC& dc, const wxBitmap& bitmap, int WXUNUSED(x), int WXUNUSED(y))
{
    wxMemoryDC dcMem;

    dcMem.SelectObjectAsSource(bitmap);
    dc.Blit(0, 0, bitmap.GetWidth(), bitmap.GetHeight(), & dcMem, 0, 0);
    dcMem.SelectObject(wxNullBitmap);
}


SplashScreenWindow::SplashScreenWindow(const wxBitmap& bitmap, wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style):
	wxPanel(parent, id, pos, size, style)
{
    m_bitmap = bitmap;
}


void SplashScreenWindow::OnPaint(wxPaintEvent& WXUNUSED(event))
{
    wxPaintDC dc(this);
    if (m_bitmap.Ok())
        wxDrawSplashBitmap(dc, m_bitmap, 0, 0);
}

void SplashScreenWindow::OnEraseBackground(wxEraseEvent& event)
{
    if (event.GetDC())
    {
        if (m_bitmap.Ok())
        {
            wxDrawSplashBitmap(* event.GetDC(), m_bitmap, 0, 0);
        }
    }
    else
    {
        wxClientDC dc(this);
        if (m_bitmap.Ok())
        {
            wxDrawSplashBitmap(dc, m_bitmap, 0, 0);
        }
    }
}
